<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Entries extends MY_Admin
{
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function Entries()
	{
		parent::MY_Admin();
		
		// Load required classes
		$this->load->model('listings_model', 'listings');
		
		// Template Settings
		$this->template->metas('title', 'Administration Backend :: Entries');
	}

	// --------------------------------------------------------------------
	
	/**
	 * List all entries
	 *
	 * @access	public
	 */
	function index()
	{
		$data['entries'] = $this->listings->get_all_entries();		
		
		$this->template->display('admin/entries/list', $data);
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * List all entries in a category
	 *
	 * @access	public
	 */
	function category($id)
	{
		$data = $this->listings->get_category_listings($id); // Gets entries and category
		
		if( count($data['entries']) == 0)
		{
			// Category doesn't exist
			$this->session->set_flashdata('msg', 'This category does not exist.');
			redirect('admin/categories');
		}
		else if($data['category']->entry_count == 0)
		{
			// Category is empty, we show a flash message
			$this->session->set_flashdata('msg', 'This category is empty.');
			redirect('admin/categories');
		}
		
		$this->template->display('admin/entries/list', $data);
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Remove an entry
	 *
	 * @param	integer	id of the entry to remove
	 * @access	public
	 */
	function remove($id)
	{
		confirm('Do you really want to remove this entry?');
				
		$this->listings->delete_entry($id);
		
		$this->session->set_flashdata('msg', 'Entry Deleted');
		redirect('admin/categories');
	}
}

/* End of file entries.php */
/* Location: ./application/controllers/admin/entries.php */